package com.fuluwa.infra.event;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

@Component
@Lazy(false)
public class GlobalEventPublisher implements ApplicationContextAware {
	private static GlobalEventPublisher publisher;
	private ApplicationContext context;

	public static GlobalEventPublisher getInstance() {
		return publisher;
	}

	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.context = applicationContext;
		publisher = this;
	}

	public void publishEvent(ApplicationEvent event) {
		this.context.publishEvent(event);
	}
}